package com.glitter.player.springbootinfluxdb;

import com.glitter.player.springbootinfluxdb.connect.InfluxDBConnect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.List;
import java.util.Map;

@SpringBootApplication
public class SpringbootInfluxdbApplication implements CommandLineRunner {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootInfluxdbApplication.class, args);
    }

    @Autowired
    private InfluxDB influxDB;
    @Override
    public void run(String... args) throws Exception {
        InfluxDBConnect influxDBConnect = influxDB.getInfluxDBConnect();
        influxDBConnect.showDatabasesList();
        //保存一年的默认策略
        influxDBConnect.createRetentionPolicy("celue","365d",1,true);

/*
        Map<String, String> tags = new HashMap<String, String>();
        tags.put("测试标签的名字", "标签值");
        Map<String, Object> fields = new HashMap<String, Object>();
        fields.put("field1", "String类型");
        // 数值型，InfluxDB的字段类型，由第一天插入的值得类型决定
        fields.put("field2", 3.141592657);
        // 时间使用毫秒为单位
        influxDBConnect.insert("test", tags, fields, System.currentTimeMillis(), TimeUnit.MILLISECONDS);*/
        Map<String, List<Object>> test = influxDBConnect.query("select * from test");
        System.out.println(test);
    }
}
